<template>
  <div class="app-container">
    <el-table :data="uploadList" style="width: 100%">
      <el-table-column label="合同名字" width="180" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.label }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下载链接" width="600" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">
            <el-link
              type="primary"
              @click="downloadFile(scope.row.download, scope.row.label)"
            >
              <span>{{
                scope.row.download === undefined
                  ? "暂无"
                  : scope.row.label
              }}</span>
            </el-link>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope"
          ><el-upload
            class="upload-demo"
            :action="action"
            :limit="1"
            :file-list="fileList"
            :headers="headers"
            :on-success="handleSuccess"
          >
            <el-button
              size="small"
              type="primary"
              @click="
                action =
                  BASE_API +
                  `/admin/sign/base-signature-file/add-or-update?key=${scope.row.value}`
              "
              >点击上传</el-button
            >
          </el-upload>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  getBaseSignatureFile,
  addOrUpdateBaseSignatureFile,
} from "@/api/system/sign";

import { getToken } from "@/utils/auth";
export default {
  name: "BaseSignatureFile",
  data() {
    return {
      BASE_API: process.env.VUE_APP_BASE_API,
      action: "",
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      uploadList: [
        // {
        //   label: "测试文件",
        //   value: "test",
        //   download: undefined,
        //   upload: undefined,
        // },
        {
          label: "工作室平台签约",
          value: "studioPlat",
          download: undefined,
          upload: undefined,
        },
        {
          label: "设计师平台签约",
          value: "stipulation",
          download: undefined,
          upload: undefined,
        },
        {
          label: "企业平台签约",
          value: "enterprisePlat",
          download: undefined,
          upload: undefined,
        },
      ],
      fileList: [],
    };
  },
  created() {
    this.getDownload();
  },
  methods: {
    getDownload() {
      for (const item of this.uploadList) {
        getBaseSignatureFile(item.value).then((res) => {
          item.download = res.filePath;
        });
      }
    },
    downloadFile(url, name) {
      this.transBlobDownload(url, name)
    },
    handleSuccess(res) {
      if (res.code == 200) {
        this.$modal.msgSuccess(res.msg);
      } else {
        this.$modal.msgError("上传失败");
      }
      this.getDownload();
      this.fileList = [];
    },
  },
};
</script>

<style>
</style>